const path = require('path');
const config = {
  //入口可以有多个
  entry: {
    // main: ['babel-polyfill','./src/main.js']
    // main: ['core-js/fn/promise','./src/main.js']
    main: ['./src/main.js']
  },
  // 打包环境：开发&&生产
  // mode: 'production',
  mode: 'development',
  // 出口：只能有一个
  output: {
    filename: '[name]-bundle.js',
    path: path.resolve(__dirname, '../dist'),
    publicPath: './'
  },
  // 本地服务器
  devServer: {
    // port: 4333,
    // https: true,
    // compress: true,
    // contentBase: "dist",
    // headers: {
    //   'fuckGay': true
    // },
    hot: true,
    open: true,
    contentBase: path.join(__dirname, "../dist"),
    overlay: true,
  },
  module: {
    rules: [
      // js loader
      {
        test: /\.js$/,
        use: [{
          loader: 'babel-loader'
        }],
        exclude: /node_modules/
      },
      // css loader
      {
        test: /\.css$/,
        use: [{
            loader: 'style-loader'
          },
          {
            loader: 'css-loader'
          }
        ]
      },
      //html loader
      {
        test: /\.html$/,
        use: [{
            loader: 'file-loader',
            options: {
              name: '[name].html'
            }
          },
          {
            loader: 'extract-loader',
          },
          {
            loader: 'html-loader',
            options: {
              attrs: ['img:src']
            }
          }
        ]
      },
      //image loader
      {
        test: /\.(jpg|gif|png)$/,
        use: [{
          loader: 'file-loader',
          options: {
            // name: 'images/[name]-[hash:8].[ext]'
            name: 'images/[name].[ext]'
          }
        }]
      }
    ]
  }
}

module.exports = config;